﻿Imports MySoft.Map.Application.Types
Imports System.Xml
Imports System.Data
Imports MySoft.Map.Data
Imports MySoft.Map.Application.Security.User

Partial Class SaleModiApply_ChgPrice_Edit_BgAfter
    Inherits Mysoft.Map.Application.Security.AppPage


    Dim MyBizParamMNG As New MySoft.PubProject.Business.BizParamMNG
    Dim MySaleMNG As New MySoft.Slxt.Business.SaleMNG
    Dim MyPubMng As New MySoft.PubProject.Business.PublicMNG

    
    Private Function InitBizParam(ByVal strProjGUID As String, ByVal strType As String) As String

        Dim dtTemp As DataTable
        Dim strSQL As String

        '1.获取管理类参数
        '是否允许手工录入成交总价("0"：不允许、"1"：允许)
        Dim strCorpModel As String = MyBizParamMNG.GetBizParamConfig("s_CorpModel", strProjGUID)
        txtCorpModel.Text = IIf(strCorpModel = "", "0", strCorpModel)

        '2.获取计算类参数
        '单价、总价保留位(0：元，1：角，2：分)
        txtPriceZero.Text = MySaleMNG.GetSysZero("s_PriceZero", strProjGUID)               '单价保留位
        txtTotalZero.Text = MySaleMNG.GetSysZero("s_TotalZero", strProjGUID)               '总价保留位

        '成交总价计算方式 (1,以标准总价为基准;2,以标准单价为基准)
        Dim strCalStd As String = MyBizParamMNG.GetBizParamConfig("s_CalStd", strProjGUID)
        txtCalStd.Text = IIf(strCalStd = "", "1", strCalStd)

        '定单失效天数
        Dim strDays As String = MyBizParamMNG.GetBizParamConfig(IIf(strType = "小订", "s_InvalidDaysXd", "s_InvalidDaysRg"), strProjGUID)
        txtEndDays.Text = IIf(strDays = "" Or Not IsNumeric(strDays), "0", strDays)

        '定单的定金标准
        Dim strEarnestStd As String = MyBizParamMNG.GetBizParamConfig(IIf(strType = "小订", "s_DjbzXd", "s_DjbzRg"), strProjGUID)
        txtEarnestStd.Text = IIf(strEarnestStd = "" Or Not IsNumeric(strEarnestStd), "0", strEarnestStd)

        '判断当前项目是否外币合同
        Dim strForeignCurrency As String = MyBizParamMNG.GetBizParamConfig("s_ForeignCurrency", strProjGUID)
        txtForeignCurrency.Text = IIf(strEarnestStd = "" Or Not IsNumeric(strForeignCurrency), "0", strForeignCurrency)


        txtDiscntLow.Text = "0"
        txtAmountLow.Text = "0"
        'End If

        Dim strEnableProjTeamForSrcMng As String = MyBizParamMNG.GetBizParamConfig("s_EnableProjTeamForSrcMng")
        txtEnableProjTeamForSrcMng.Text = IIf(strEnableProjTeamForSrcMng = "", "1", strEnableProjTeamForSrcMng)
    End Function

    '获取付款方式的信息：定金、按揭、公积金比例，是否扣除定金
    Private Function GetPayFormInfo(ByVal strPayformName As String, ByVal strProjGUID As String) As String
        Dim strSQL, strSQLTemp As String
        Dim dtTemp As DataTable
        Dim strPayformZl, strEarnestStd, strEarnestZl, strAjZl, strGjjZl As String
        Dim strPayFormGUID As String


        '获取付款方式的贷款精确度
        strSQL = "SELECT TOP 1 AjZero,GjjZero FROM s_PayForm " & _
                 " WHERE payformguid in " & "(select payformguid from s_PayForm where payformname='" & strPayformName & "' and projguid='" & strProjGUID & "')"
        dtTemp = MyDB.GetDataTable(strSQL)
        If dtTemp.Rows.Count = 0 Then Return ""
        txtAjZero.Text = dtTemp.Rows(0)("AjZero")         '按揭精确度（直接截断）
        txtGjjZero.Text = dtTemp.Rows(0)("GjjZero")       '公积金精确度（直接截断）

        '获取付款明细款项的信息
        strSQLTemp = "SELECT top 1 Rate,Amount,IsDeductEarnest FROM s_Paydetail WHERE payformguid in " & "(select payformguid from s_PayForm where payformname='" & strPayformName & "' and projguid='" & strProjGUID & "')"

        '获取定金明细的信息
        strSQL = strSQLTemp & " AND FeeSort='非贷款类房款' AND ItemName='定金'"
        dtTemp = MyDB.GetDataTable(strSQL)
        If dtTemp.Rows.Count > 0 Then
            txtEarnestRate.Text = dtTemp.Rows(0)("Rate").ToString()
        End If

        '获取按揭明细的信息
        strSQL = strSQLTemp & " AND FeeSort='贷款类房款' AND ItemName = '银行按揭'"
        dtTemp = MyDB.GetDataTable(strSQL)
        If dtTemp.Rows.Count > 0 Then
            txtAjRate.Text = dtTemp.Rows(0)("Rate").ToString()
            txtAjIsDeductEarnest.Text = dtTemp.Rows(0)("IsDeductEarnest").ToString()
            If dtTemp.Rows(0)("Rate") > 0 OrElse dtTemp.Rows(0)("Amount") > 0 Then
                txtIsAj.Text = "1"
            End If
        End If

        '获取公积金明细的信息
        strSQL = strSQLTemp & " AND FeeSort='贷款类房款' AND ItemName = '公积金'"
        dtTemp = MyDB.GetDataTable(strSQL)
        If dtTemp.Rows.Count > 0 Then
            txtGjjRate.Text = dtTemp.Rows(0)("Rate").ToString()
            txtGjjIsDeductEarnest.Text = dtTemp.Rows(0)("IsDeductEarnest").ToString()
            If dtTemp.Rows(0)("Rate") > 0 OrElse dtTemp.Rows(0)("Amount") > 0 Then
                txtIsGjj.Text = "1"
            End If
        End If
    End Function

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        Dim strMode, strOid, strOrderType, strProjGUID, strRoomGUID, strYwFlag, strUserGUID, StrUserName As String
        Dim strSQL As String
        Dim dtTemp As DataTable
        Dim strToDay, strPayformName As String

        '1.接收公用参数
        strMode = Request.QueryString("mode")                   '模式(1:新增　2:编辑 3:查看)
        strYwFlag = Request.QueryString("ywflag")               '业务标识： new(新增定单)、transold(新增定单，从旧定单引入价格)、transnew(新增定单，从房间引入新价格)
        strProjGUID = Request.QueryString("projguid")           '项目guid
        strOrderType = Request.QueryString("type")              '定单类型：1、小订 2、认购(新增时指定要新增的定单类型)
        If Not Request.QueryString("UserGUID") Is Nothing Then
            strUserGUID = Request.QueryString("UserGUID")
            StrUserName = Request.QueryString("UserName")
        End If

        '2.获取业务参数
        InitBizParam(strProjGUID, strOrderType)
     
        '编辑模式、查看模式
        strOid = Request.QueryString("saleguid")

        If strOrderType = "合同" Then
            strSQL = "select QSDate,roomguid,PayformName from s_contract where contractguid='" & strOid & "'"
        Else
            strSQL = "select QSDate,roomguid,PayformName from s_order where orderguid='" & strOid & "'"
        End If

        dtTemp = MyDB.GetDataTable(strSQL)
        If dtTemp.Rows.Count > 0 Then
            strRoomGUID = dtTemp.Rows(0)("roomguid").ToString
            strToDay = dtTemp.Rows(0)("QSDate").ToString
            strPayformName = dtTemp.Rows(0)("PayformName").ToString
        End If

        Dim strBldGUID As String                '主房间楼栋GUID
        If strRoomGUID <> "" Then
            strSQL = " SELECT BldGUID,djarea,isnull(convert(varchar(50),StatusChgGUID),'')  as StatusChgGUID  from p_Room WHERE RoomGUID='" & strRoomGUID & "'"

            dtTemp = MyDB.GetDataTable(strSQL)
            If dtTemp.Rows.Count > 0 Then
                strBldGUID = dtTemp.Rows(0)("BldGUID").ToString
                txtDjArea.Text = dtTemp.Rows(0)("djarea").ToString
                txtStatusChgGUID.Text = dtTemp.Rows(0)("StatusChgGUID").ToString
            End If
        End If


        strBldGUID = MyDB.GetDataItemString(strSQL)
        appForm.DefaultValueXml = "<xml>" & _
           "<PayformName sql=""SELECT PayformName as [value],PayformName as text FROM s_Payform WHERE ProjGUID='" & strProjGUID & "' AND (CONVERT(varchar(4000),ISNULL(BldGUIDList,''))='' OR BldGUIDList LIKE '%" & strBldGUID & "%') " & _
            " AND (isnull(bgndate,'1900-01-01')&lt;='" & strToDay & "' AND isnull(EndDate,'9999-12-31')&gt;'" & strToDay & "') AND exists (select top 1 1 from s_PayDetail where s_PayDetail.PayFormGUID=s_Payform.PayFormGUID) ORDER BY PayformName"" />" & _
            "<appForm_ZxBz sql=""SELECT ZxBzGUID as [value],ZxBz as text FROM p_ZxbzSet WHERE ProjGUID='" & strProjGUID & "' ORDER BY ZxBz"" />" & _
            "</xml>"

        If Request.QueryString("xml") = "SaleModiApply_ChgPrice_Edit_BgAfter_Edit.xml" Then
            '初始化折扣列表
            txtDiscntListXml.Text = MySaleMNG.GetOCDiscountListXml(Request.QueryString("oid"), "1", "1")
        Else
            '初始化折扣列表
            txtDiscntListXml.Text = MySaleMNG.GetOCDiscountListXml(strOid, "1")
        End If
       


        '初始化附属房间列表
        txtFsfcListXml.Text = MySaleMNG.GetOCAttachRoomListXml(strOid, "1")

        '业务员信息
        txtSaleListXml.Text = MySaleMNG.GetOC2SaleListXml(strOid, "1")


        '业务标识
        txtYwFlag.Text = strYwFlag

        txtIsjydjx.Text = IIf(Mysoft.Slxt.Business.PublicMng.CheckDjManageEnable(), 1, 0)
        If txtIsjydjx.Text = "1" Then
            txtIsjydjx.Text = MyDB.GetDataItemString("SELECT ParamValue FROM dbo.myBizParamOption WHERE ParamName ='s_EnableDjXy'")
        End If

        '付款方式的信息
        If strPayformName <> "" Then
            GetPayFormInfo(strPayformName, strProjGUID)
        End If

        txtGetBindRoomguids.Text = XSXC_XMLHTTP.GetBindRoomguids(strRoomGUID)
    End Sub

    Protected Overrides Sub ConfigureForm()
        appForm.Execute()
    End Sub


End Class
